package server;

import hibernate.HibernateUtil;
import controller.*;
import controller.RemoteObject;

import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;

public class Server extends UnicastRemoteObject implements ServerInterface{
	
	protected Server() throws RemoteException {
		super();
	}

	private static final long serialVersionUID = 1L;

	public int sum(int a,int b) throws RemoteException
	  {
	     return a + b; // esta implementado aca, nosotros lo vamos a implementar en beans...
	  }
	
	public static void main(String args[]) throws AlreadyBoundException
	  {
	      try
	      {
			//asigna el security manager
	        //System.setSecurityManager(new RMISecurityManager());
	        // Crea una instancia del objeto remoto.
	  		
				RemoteObject objetoRemoto = new RemoteObject();
				
				// Create new Registry, allocate it in a Server Port.
				
				LocateRegistry.createRegistry(1099);
				Registry registry = LocateRegistry.getRegistry(1099);
				registry.bind("//localhost/SAMPLE-SERVER", objetoRemoto);
				System.out.println("Remote Object bound");
				
				// Inicia el registry y publica el objeto remoto.
				
				//new HibernateUtil(); // Para ver las tablas en SQL.

	        System.out.println("esperando.....");
	      }
	      catch (RemoteException re)  {
	         System.out.println("Remote exception: " + re.toString());  }
	  }

}
